package yartiss.engine.simulation.scheduling.policies;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import yartiss.engine.simulation.ISchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.dp.EDFMultiProcSchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.dp.EDFSchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.dp.EDLSchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.dp.EDegSchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.dp.EHPDP1SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.dp.EHPDP2SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.dp.EHPDP4SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.dp.EHPDP5SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.dp.LaxityGraphMultiProcSchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.EHPFP1SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.EHPFP2SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.EHPFP3SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.EHPFP4SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.EHPFP5ScheculingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.EHPFP6SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.EHPFP7SchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.FPLSchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.FPMultiProcSchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.FPSchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.FPegSchedulingPolicy;
import yartiss.engine.simulation.scheduling.policies.fp.FPegTest;
import yartiss.engine.simulation.scheduling.policies.tools.DPSlackEnergyManager;
import yartiss.engine.simulation.scheduling.policies.tools.DPSlackTimeManager2;
import yartiss.engine.simulation.scheduling.policies.tools.FPSlackEnergyManager;
import yartiss.engine.simulation.scheduling.policies.tools.FPSlackEnergyManager1;
import yartiss.engine.simulation.scheduling.policies.tools.FPSlackTimeManager;

public class SchedulingPolicyFactory {
	
	private static final Map<String, ISchedulingPolicy> policies;
	private static List<ISchedulingPolicy> policiesLis = new ArrayList<ISchedulingPolicy>();
	
	static {
		policiesLis.add(new EDegSchedulingPolicy(new DPSlackTimeManager2(), new DPSlackEnergyManager()));
		policiesLis.add(new EDFSchedulingPolicy());
		policiesLis.add(new EDFMultiProcSchedulingPolicy());
		policiesLis.add(new EDLSchedulingPolicy(new DPSlackTimeManager2()));
		policiesLis.add(new EHPDP1SchedulingPolicy());
		policiesLis.add(new EHPDP1SchedulingPolicy());
		policiesLis.add(new EHPDP2SchedulingPolicy());
		policiesLis.add(new EHPDP4SchedulingPolicy(new DPSlackTimeManager2()));
		policiesLis.add(new EHPDP5SchedulingPolicy(new DPSlackTimeManager2()));
		policiesLis.add(new FPSchedulingPolicy());
		policiesLis.add(new FPMultiProcSchedulingPolicy());
		policiesLis.add(new FPLSchedulingPolicy());
		policiesLis.add(new FPegSchedulingPolicy(new FPSlackTimeManager(), new FPSlackEnergyManager1()));
		policiesLis.add(new FPegTest(new FPSlackEnergyManager1()));
		policiesLis.add(new EHPFP1SchedulingPolicy());
		policiesLis.add(new EHPFP2SchedulingPolicy());
		policiesLis.add(new EHPFP3SchedulingPolicy(new FPSlackTimeManager()));
		policiesLis.add(new EHPFP4SchedulingPolicy(new FPSlackTimeManager()));
		policiesLis.add(new EHPFP5ScheculingPolicy(new FPSlackTimeManager()));
		policiesLis.add(new EHPFP6SchedulingPolicy( new FPSlackEnergyManager()));
		policiesLis.add(new EHPFP7SchedulingPolicy(new FPSlackTimeManager(), new FPSlackEnergyManager()));
		policiesLis.add(new LaxityGraphMultiProcSchedulingPolicy());
		
		policies = new HashMap<String, ISchedulingPolicy>();
		
		for (ISchedulingPolicy policy : policiesLis) {
			policies.put(policy.getPolicyName(), policy);
		}
	}
	
	public static void registerPolicy(ISchedulingPolicy policy){
		policies.put(policy.getPolicyName(), policy);
	}
	
	public static ISchedulingPolicy getInstance(String polycyName) {
		if(policies.containsKey(polycyName)){
			return policies.get(polycyName).newInstance();
		}
		throw new IllegalArgumentException(polycyName);
	}

	public static String[] getAvailableSchedulingPoliciesNames() {
		String [] availible = new String [policies.size()];
		int i=0;
		for (String policy : policies.keySet()) {
			availible[i++] = policy;
		}
		return availible;
	}
}
